package z.myServer;

public class Change {
	public static byte[] intToByte(int num) {
		byte[] buffer = new byte[4];
		//https://blog.csdn.net/u013556056/article/details/81019509
		//byteToint鐨勬柟娉曚粙缁�
		//姣忎釜byte鍙湁8涓綅锛屼粠浣庝綅鍙栵紙浠庡彸寰�宸︼級8涓紝鎵�浠ラ渶瑕佺Щ浣嶃��
		//杩欐牱鏁村瀷杞崲鎴愬瓧鑺傛暟缁勫氨瀹屾垚浜�
		for (int i = 0; i < 4; i++) {
			buffer[i] = (byte) (num >> 8 * i);
		}
		return buffer;
	}
	
	public static int byteToInt(byte[] buffer, int offset) {
		int num = 0;
		for (int i = 0; i < 4; i++) {
			num += (int) (buffer[i + offset] << 8 * i);
		}
		System.out.println("len: " + num);
		return num;
	}
}
